﻿using Microsoft.SharePoint;
using System.Modules.SharePoint.Constants;

namespace System.Modules.SharePoint.Contracts.DTO
{
    /// <summary>
    /// Use to populate SP Query Value Tag
    /// </summary>
    public class SPQueryValue
    {
        #region Properties
        /// <summary>
        /// SPFieldType
        /// </summary>
        public SPFieldType FieldType { get; set; }
        /// <summary>
        /// String value
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// IncludeTimeValue
        /// </summary>
        public bool? IncludeTimeValue { get; set; }
        #endregion

        #region Constructor
        /// <summary>
        /// Default Constructor
        /// </summary>
        public SPQueryValue() { }

        /// <summary>
        /// Initiate a SP Query Value object
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        public SPQueryValue(SPFieldType type, string value)
        {
            FieldType = type;
            Value = value;
        }
        #endregion

        #region Implicit Operators
        /// <summary>
        /// Implicit conversion operator to string
        /// </summary>
        /// <param name="value">The SP Query Value</param>
        /// <returns>A string representation of the SP Query Value object</returns>
        public static implicit operator string(SPQueryValue value)
        {
            return value.ToString();
        }
        #endregion

        #region Override
        /// <summary>
        /// Overrides To String
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return IncludeTimeValue.HasValue ? string.Format(SPQueryTemplates.VALUE_INCLUDE_TIME, FieldType, IncludeTimeValue.Value.ToString().ToUpper(), Value) : String.Format(SPQueryTemplates.VALUE, FieldType, Value);
        }
        #endregion
    }
}
